# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('libyaml' 'libyaml-devel')
pkgver=0.1.7
pkgrel=1
pkgdesc="YAML 1.1 library"
arch=('i686' 'x86_64')
url="https://pyyaml.org/wiki/LibYAML"
license=('MIT')
source=(https://pyyaml.org/download/libyaml/yaml-$pkgver.tar.gz
    'yaml-0.1.7-fix-undefined.patch'
    'yaml-0.1.7-msys2.patch')
sha256sums=('8088e457264a98ba451a90b8661fcb4f9d6f478f7265d48322a196cec2480729'
            '6fae0d088cd67ad61a3ec83c03116bfb829276201a18ba583a9acc230e2f57f6'
            'bea0e3d9d01b2769abb71c358babb2c2c98cc98ddb9ac2cd5dd77ed2932c2212')

prepare() {
  cd "$srcdir/yaml-$pkgver"

  patch -p1 -i ${srcdir}/yaml-0.1.7-fix-undefined.patch
  patch -p1 -i ${srcdir}/yaml-0.1.7-msys2.patch

  autoreconf -fi
}

build() {
  cd "$srcdir/yaml-$pkgver"
  ./configure --build=${CHOST} --prefix=/usr
  make
  setup
}

setup() {
  cd "$srcdir/yaml-$pkgver"
  make DESTDIR="$srcdir/dest" install
  install -m644 -D LICENSE $srcdir/dest/usr/share/licenses/$pkgname/LICENSE
}

package_libyaml() {
  groups=('libraries')

  install -dm755 $pkgdir/usr/bin
  install -m755 -t ${pkgdir}/usr/bin $srcdir/dest/usr/bin/*.dll
  cp -rf $srcdir/dest/usr/share ${pkgdir}/usr/
}

package_libyaml-devel() {
  groups=('development')
  depends=("libyaml=${pkgver}")

  install -dm755 $pkgdir/usr
  cp -rf $srcdir/dest/usr/include ${pkgdir}/usr/
  cp -rf $srcdir/dest/usr/lib ${pkgdir}/usr/
}
